//
//  TestViewFactory.swift
//  Runner
//
//  Created by 李旭峰 on 2020/7/9.
//

import UIKit
import Flutter

public class TestViewFactory: NSObject,FlutterPlatformViewFactory {
    var messenger: FlutterBinaryMessenger
    public static func register(with register:FlutterPluginRegistry){
        let pluginKey = "test_view_plugin"
        if register.hasPlugin(pluginKey) { return }
        let registrar = register.registrar(forPlugin: pluginKey)
        let messenger = registrar.messenger() as! (NSObject & FlutterBinaryMessenger)
        let factory = TestViewFactory(messenger: messenger)
        registrar.register(factory, withId: TestView.viewName)
    }
    public static func register(withRegistrar registrar:FlutterPluginRegistrar){
        let messenger = registrar.messenger() as! (NSObject & FlutterBinaryMessenger)
        let factory = TestViewFactory(messenger: messenger)
        registrar.register(factory, withId: TestView.viewName)
    }
    @objc public init(messenger:(NSObject & FlutterBinaryMessenger)) {
        self.messenger = messenger
        super.init()
    }
    public func createArgsCodec() -> FlutterMessageCodec & NSObjectProtocol {
        return FlutterStandardMessageCodec.sharedInstance()
    }
    public func create(withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: Any?) -> FlutterPlatformView {
        return TestView(frame, viewID: viewId, args: args, binaryMessenger: self.messenger)
    }
}
